#include "rte_ring.h"


struct rte_ring *ring;
void *consumer(void *arg)
{
	int p_id = (int)arg;
	while(1){
		int *test;
		int ret = rte_ring_mc_dequeue(ring, &test);
		if(ret == 0)
			free(test);
	}
}
void *producer(void *arg)
{
	int c_id = (int)arg;
	while(1){
		int *test = malloc(16);
		if(test == NULL)
			continue;
		int ret = rte_ring_mp_enqueue(ring, test);
		if(ret != 0){
			free(test);
		//	printf("thread %d enqueue failed\n", c_id);
		}
	}
}
int main()
{
	ring = rte_ring_create("dd", 16777216, 0, 0); 
	int cnt =0;
	pthread_t tidp;
	pthread_create(&tidp, NULL, producer, (void*)cnt++);
	pthread_create(&tidp, NULL, producer, (void*)cnt++);
	pthread_create(&tidp, NULL, consumer, (void*)cnt++);	
	pthread_create(&tidp, NULL, consumer, (void*)cnt++);	
	
	while(1){
		sleep(1);
		printf("free count:%d\n", rte_ring_free_count(ring));
	}
	return 0;
}
